package com.yangjie.common.service;

import java.util.Locale;

import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

@Component("messageProvider")
@Scope(value = WebApplicationContext.SCOPE_SESSION)
public class MessageProvider {
	
	@Inject
	@Qualifier("guiMessageSource")
	ReloadableResourceBundleMessageSource messageSource = null;
	
	private Locale locale = null;
	

	public Locale getLocale() {
		return locale;
	}


	public void setLocale(Locale locale) {
		this.locale = locale;
	}

	public String getMessage(String code) {
		return messageSource.getMessage(code, null, locale);
	}

	public String getMessage(String code, Object[] args) {
		return messageSource.getMessage(code, args, locale);
	}
}
